//
//  TestLayouting.cpp
//  NanoOSX
//
//  Created by Jeppe Nielsen on 10/22/13.
//  Copyright (c) 2013 Jeppe Nielsen. All rights reserved.
//

#include "Engine.hpp"
#include "Gui.hpp"
#include "LayoutSystem.hpp"

#include <algorithm>

using namespace Nano;

class TestLayouting : public GameState {
    
    void Initialized() {
        
        gui.Initialize("images.png", "images.xml", 1024, Viewport(), Input);
        GameObject* font = gui.CreateFont("OtherFont.fnt", "OtherFont");
        
        window = gui.CreateControl(0, "Button", Vector2(0,0), Vector2(400,400));
        window->AddComponent<Draggable>();
        window->AddComponent<Layouter>()->Cells = 2;
        window->GetComponent<Layouter>()->Margin = 30;
        
        GameObject* content = gui.CreateControl(window, "wood");
        content->GetComponent<Layoutable>()->Fill = Vector2(1,5.0f);
        content->RemoveComponent<Touchable>();
        
        GameObject* topBar = gui.CreateControl(window, "Button");
        topBar->RemoveComponent<Touchable>();
    
        window->GetComponent<Transform>()->Anchor = { 200,200 };
        
        GameObject* label = gui.CreateLabel(window, 0, 400, font, "Testing font", 20);
        label->GetComponent<Label>()->HAlignment = Font::Center;
        label->GetComponent<Label>()->VAlignment = Font::Middle;
        
    }
    
    void Update(float dt) {
        
        static float rot = 0;
        
        rot+=dt * 0.2f;
        
        window->GetComponent<Transform>()->Rotation = rot;
        
        //control->GetComponent<Layouter>()->Margin = Vector2(Input.GetTouchPosition(0).x, Input.GetTouchPosition(0).y);
        
        gui.Update(dt);
    }
    
    void Render() {
        glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
        glDisable(GL_CULL_FACE);
        
        gui.Render();
    }
    
    Gui gui;
    GameObject* window;
};

/*
int main() {
    Engine e;
    e.Start<TestLayouting>();
}
 */






